from threading import Thread
import asyncio


class MyThread(Thread):

    def __init__(self):
        super(MyThread, self).__init__()
        self.__task = None

    async def task1(self):
        print("携程1::开始")
        await asyncio.sleep(3)
        print("携程1::结束")

    async def task2(self):
        print("携程2::开始")
        await asyncio.sleep(3)
        print("携程2::结束")

    async def main(self):
        self.__task = [self.task1(), self.task2()]
        res = await asyncio.gather(*self.__task)
        return res

    def run(self) -> None:
        print("子线程开始!")
        loop = asyncio.new_event_loop()
        loop.run_until_complete(self.main())
        print("子线程结束!")

    def getAsyncio(self):
        return self.__task


if __name__ == '__main__':
    print("主进程开始!")
    thread = MyThread()
    thread.start()
    print(thread.getAsyncio())
    thread.join()
    print("主线程结束!")
